//
// Unihan Input Method
//
// Copyright © 2002-2007 Sun Wah Linux Ltd.
//
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the GNU Lesser General Public License as
// published by the Free Software Foundation; either version 2.1 of the
// License, or (at your option) any later version.
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
// Lesser General Public License for more details.
//
// You should have received a copy of the GNU Lesser General Public
// License along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307
// USA
//
// $Id: table.h 805 2007-07-31 16:21:54Z roger $
//

#ifndef _TABLE_H
#define _TABLE_H

#include <unihan_im.h>
#include "shuangpin.h"
#include "frequence.h"
#include "cands_factory.h"

#define PINYIN 1
#define SHUANGPIN 2

typedef struct {
	char name[7];
} KeyName;

typedef struct {
	int offset;
} FastIdx;

typedef struct {
	int p;
} Priority;

typedef struct {
	int keyOff;
	int valOff;
	int frqOff;
	int maxFrqOff;
} KeyValTab;

#define NUM_KEYS 0x60


typedef struct {
	int numKey;
	int numVal;
	char *keyList;
	char *valList;
	int *maxFrqList;
	int *frqList;
	KeyName *keyName;
	FastIdx *fastIdx;
	KeyValTab *kvtab;
	unsigned long hints;
	int preeditMax;

	void *tabFileMMap;
	void *frqFileMMap;
	size_t tabFileSize;
	size_t frqFileSize;

	SPTable *sp_table;	/* 2004.2.19 arren */
	int PYMode;		/* PINYIN, SHUANGPIN */
	int FreqMode;
	int IllMode;		/* illegibility mode */

	SymbolUserTable *sut;
	int numSut;
	WordUserTable *wut;
	int numWut;
	int chinese_mode;
	int is_full;
	int is_CH;
} TableDataPerDesktop;

#define PREEDIT_LEN_MAX 256

typedef struct {
	char *key;
	char *cand;
	int order;
} Candidate;

typedef struct {
	int (*handle_key_event)(UnihanIM *uim, IMKeyEvent *ev);

	char keybuf[PREEDIT_LEN_MAX+1];		/* input key buf 2004.2.20 arren */
	char preedit[PREEDIT_LEN_MAX+1];
	short preeditLen;

	int numCands;
	int numExactCands;
	int highIdx;
	int lowIdx;
	int exactIdx;
	int luCurrCandOffset;

	int maxPrio;
	SPFlag sp_flag;		/* shengmu/yunmu flag 2004.2.20 arren */
	FreqCandList *frqCandList;
	int frqAppend;
	InputCell *ic;
	//IllTree *it;
	CandFactory *candFactory;

	int lookupShown;

	Candidate *cands;
} TableDataPerSession;


#define idx(x) ((x)-0x20)
#define TABFILE_SIG "UnihanGenTab1"

typedef struct {
	char key;
	char *punc1;	//width = 0 & puncce = 1
	char *punc2;	//width = 1 & puncce = 0
	char *punc3;	//width = 1 & puncce = 1
} PunctuationList;

static PunctuationList puncList[] = {	
	{ '0', NULL, "０", "０" },
    { '1', NULL, "１", "１" },
    { '2', NULL, "２", "２" },
    { '3', NULL, "３", "３" },
    { '4', NULL, "４", "４" },
    { '5', NULL, "５", "５" },
    { '6', NULL, "６", "６" },
    { '7', NULL, "７", "７" },
    { '8', NULL, "８", "８" },
    { '9', NULL, "９", "９" },	
	{ ',',  "，", "，", "，" },
	{ '.',  "。", "．", "。" },
	{ '\\', "、", "＼", "、" },
	{ '`',  "`", "｀", "｀" },
	{ '\'', "‘", "＇", "‘" },
	{ '\'', "’", "＇", "’" },
    { '[', "[", "［", "【" },
    { ']', "]", "］", "】" },
    { '<', "〈", "＜", "《" },
    { '>', "〉", "＞", "》" },
    { '!', "！", "！", "！" },
    { '"', "“", "＂", "“" },
    { '"', "”", "＂", "”" },
    { '#', "#", "＃", "＃" },
    { '$', "￥", "＄", "￥" },
    { '%', "%", "％", "％" },
    { '&', "―", "＆", "―" },
    { '(', "（", "（", "（" },
    { ')', "）", "）", "）" },
    { '*', "*", "＊", "＊" },
    { '+', "+", "＋", "＋" },
    { '_', "――", "＿", "――" },
    { '/', "/", "／", "／" },
    { ':', "：", "：", "：" },
    { ';', "；", "；", "；" },
    { '=', "=", "＝", "＝" },
    { '-', "-", "－", "－" },
    { '?', "？", "？", "？" },
    { '@', "・", "＠", "・" },
    { '^', "……", "＾", "……" },
    { '{', "{", "｛", "｛" },
    { '}', "}", "｝", "｝" },
    { '|', "|", "｜", "｜" },
    { '~', "~", "～", "～" },
    {'\0', "\0", "\0", "\0" }
};

int unihan_im_module_init(void);
void unihan_im_module_done(void);
int unihan_im_module_get_info(UnihanIMModuleArgList *args);
void find_candidates(UnihanIM *uim);


#endif /* _TABLE_H */

// vi:ts=4:nowrap:cin:expandtab
